// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: qiulin_JXGM ql1746365080@gmail.com
 * @Date: 2024-10-10 14:41:52
 * @LastEditors: qiulin 1746365080@qq.com
 * @LastEditTime: 2025-01-08 19:48:05
 * @FilePath: \SGFEM\Import\BDFImport\ControlData\SUBCASE\SubcaseDelimiters.cpp
 */

#include "SubcaseDelimiters.h"

#include <cstring>
#include <iostream>

#include "Utility/Logging/SGLogger.h"

CONTROLDATA_ENTRY_PARSER_REG (SUBCASE)

SG::DataStructure::Common::Status SG::Import::BDF::CONTROLDATA::ParseSUBCASE (SG::DataStructure::FEM::Subcase::ControlInfo& controlInfo,
                                                                              SG::Utility::SGParameter&                     subcase)
{
    SG::Utility::SGParameter ParameterSUBCASE;
    ParameterSUBCASE.AddString (SG::DataStructure::FEM::Subcase::SC_MAINKEY, controlInfo.m_Vaule);
    if (controlInfo.m_vecKeys.size () != 0)
    {
        ParameterSUBCASE.AddStringArray (SG::DataStructure::FEM::Subcase::SC_VECTORKEY, controlInfo.m_vecKeys);
    }
    if (controlInfo.m_mapKeys.size () != 0)
    {
        SG::Utility::SGParameter mapParameter;
        for (auto iter : controlInfo.m_mapKeys)
        {
            mapParameter.AddString (iter.first, iter.second);
        }
        ParameterSUBCASE.AddValue (SG::DataStructure::FEM::Subcase::SC_MAPKEY, mapParameter);
    }
    subcase.AddValue ("SUBCASE", ParameterSUBCASE);

    if (SG::Import::BDF::CaseDataEntryParserFactory::GetInstance ()->m_FirstSubcaseID == 0)
    {
        SG::Import::BDF::CaseDataEntryParserFactory::GetInstance ()->m_FirstSubcaseID = convertToI64 (controlInfo.m_Vaule);
    }
    return SG::DataStructure::Common::Status::STATUS_Success;
}
